import { Component } from "react";
import {Lucy, Andy} from './components'

export default class CrossComponentCommunication extends Component {
    state = {
        data: ''
    }

    // 传给子组件的函数，用于接受子组件传来的 data
    eventBus = (newData) => {
        this.setState({
            data: newData
        })
    }

    render(){
        return (
            <div>
                {/* 将函数传给子组件，用于接受子组件传来的 data */}
                <Lucy bus = {this.eventBus}></Lucy>
                {/* 将兄弟组件传来的data，传给自己 */}
                <Andy {...this.state}></Andy>
            </div>
        )
    }
}